package com.bawei.common.rabbit.domain;

import com.bawei.common.core.utils.uuid.IdUtils;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;

/**
 * @author 蒋柏林
 * @version 1.0
 * @project mall-cloud
 * @date 2022/10/21 15:54:14
 */
public class Message<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 消息ID
     */
    private String id;

    /**
     * 消息创建时间
     */
    private long createTime;

    /**
     * 消息主题
     */
    private T body;

    public Message() {
    }

    public Message(String id , T body) {
        this.id = id;
        this.createTime = System.currentTimeMillis();
        this.body = body;
    }

    /**
     * 自动生成消息ID
     * @param body 消息主题
     * @return
     */
    public static <T> Message<T> builderMsg(T body){
        return new Message(IdUtils.fastUUID(), body);
    }

    /**
     * 生成消息主题
     * @param id 唯一表示
     * @param body 消息主体
     * @return
     */
    public Message builderMsg(String id ,T body){
        return new Message(id, body);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }
}
